package manager

import (
	"NovelBook/logic/account"
	"NovelBook/models/res"
	"NovelBook/utils/auth"
	"NovelBook/utils/response"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

// WorkerRegister Worker 注册接口
// 废弃原来的接口，worker注册也需要验证码？

func WorkerRegister(c *gin.Context) {
	idAny, exist := c.Get(auth.ManagerIDKey)
	id := idAny.(uint)
	if !exist || id < 1 {
		response.Fail(c, http.StatusUnauthorized, response.CodeTokenInvalid)
		return
	}

	var Info res.RegisterInfo
	err := c.ShouldBindJSON(&Info)
	log.Println(Info)
	if err != nil {
		response.Fail(c, http.StatusBadRequest, response.CodeParamsInvalid)
		log.Println("bind err : ", err)
		return
	}

	// 调用Register
	err = account.Register(Info, account.WORKER)

	if err != nil {
		response.FailWithMsg(c, http.StatusServiceUnavailable, response.CodeSystemBusy, err.Error())
		return
	}

	response.Success(c, nil)
}
